﻿#include "ServiceHandle.h"
#include <windows.h>

// 构造函数接管句柄所有权
ServiceHandle::ServiceHandle(SC_HANDLE handle) : m_handle(handle) {}

// 析构时自动释放句柄
ServiceHandle::~ServiceHandle() {
  if (m_handle) {
    CloseServiceHandle(m_handle);
  }
}

// 隐式转换运算符
ServiceHandle::operator SC_HANDLE() const { return m_handle; }

ServiceHandle::operator bool() const { return m_handle != NULL; }